/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bsc.war.test;

import bsc.ejb.entity.Person;
import bsc.ejb.entity.ScoreCard;
import bsc.ejb.metadata.SMTP;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import bsc.war.mail.MailUtils;
import bsc.war.mail.SendMailTask;
import java.util.Timer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author memozac
 */
public class SendMail extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        try {
            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");
            SMTP smtp = delegate.findSMTP(1L);
            ScoreCard scoreCard = delegate.findScoreCard(1L);
            Person person = delegate.findPerson(1L);

            Timer timer = new Timer();
            timer.schedule(new SendMailTask(person, scoreCard, MailUtils.Type.SCORECARD_DASHBOARD, smtp, getServletContext()), 1);
            
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}
